package com.jlobu.activity;

import androidx.appcompat.app.AppCompatActivity;
import butterknife.ButterKnife;
import butterknife.OnClick;

import android.os.Bundle;

import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.example.jlobu.R;
import com.jl.obulibrary.bean.CarAllBean;
import com.jl.obulibrary.bean.CardBean;
import com.jl.obulibrary.bean.ObuBean;
import com.jl.obulibrary.sdk.KeChuang_SDK;
import com.jl.obulibrary.sdk.SDK_RSU;
import com.jxhc.rsudriver.model.TransferChannel_res;


public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        KeChuang_SDK.power(1);
        KeChuang_SDK.Init();


    }


    /**
     * @param
     * @return
     * @description 点击事件
     * @author 智江鹏
     * @date 2025-03-24
     * @version v1.00
     */

    @OnClick({R.id.button_initialization, R.id.button_bst, R.id.button_active, R.id.button_pay, R.id.button_eventreport, R.id.button_selftest})
    public void onClick(View view) {
        switch (view.getId()) {

            case R.id.button_bst:
                try {

                    //发送BST唤醒OBU
                    SDK_RSU.SendBST();
                    SDK_RSU.OffGetSecure();
                    SDK_RSU.SendSetMMI();
                    SDK_RSU.SendEVENTREPORT();
                    Toast.makeText(this, "扫描成功 " , Toast.LENGTH_SHORT).show();
                    ObuBean obuBean = SDK_RSU.getObuBean();
                    Log.e("OBU信息", obuBean.toString());
                    CardBean cardBean = SDK_RSU.getCardBean();
                    Log.e("卡片信息", cardBean.toString());
                    CarAllBean carAllBean = SDK_RSU.getCarAllBean();
                    Log.e("卡片信息", carAllBean.toString());

                } catch (Exception e) {
                    Log.e("OBU检测", "发生异常："+e.getMessage());
                    Toast.makeText(this, "发生异常："+e.getMessage(), Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.button_active:
                //脱机激活
                try {
                    //发送BST唤醒OBU
                    SDK_RSU.SendBST();
                    SDK_RSU.OffActive();
                    SDK_RSU.SendSetMMI();
                    SDK_RSU.SendEVENTREPORT();
                } catch (Exception e) {
                    Log.e("OBU激活", "发生异常："+e.getMessage());
                }

                break;
            case R.id.button_pay:
                //脱机交易

                try {
                    //发送BST唤醒OBU
                    SDK_RSU.SendBST();
                    SDK_RSU.OffPay();
                    SDK_RSU.SendSetMMI();
                    SDK_RSU.SendEVENTREPORT();
                } catch (Exception e) {
                    Log.e("OBU交易", "发生异常："+e.getMessage());
                }
                break;
            case R.id.button_eventreport:

                try {
                    SDK_RSU.SendBST();
                    TransferChannel_res transferChannel_res = SDK_RSU.SendTransferChannelCustom("01","68FFFFFF40779105010014800100004F9340C634864E4D220000");
                    String data = transferChannel_res.getData();
                    Log.e("111", "返回数据"+data);
                    SDK_RSU.SendSetMMI();
                    SDK_RSU.SendEVENTREPORT();
                } catch (Exception e) {
                    e.printStackTrace();
                }




                break;
            case R.id.button_initialization:
                try {
//                    SDK_RSU.SendBST();
                    String version = SDK_RSU.SendReadVersion();

                    Log.e("111", "返回数据"+version);
//                    SDK_RSU.SendSetMMI();
//                    SDK_RSU.SendEVENTREPORT();
                } catch (Exception e) {
                    e.printStackTrace();
                }

                break;
            case R.id.button_selftest:


                break;
        }
    }
}